package com.sunxd.limit.core.handlers.joinAct;

import com.sunxd.limit.core.annotation.LimitAnnotation;
import com.sunxd.limit.beans.constants.LimitAnnotationGroup;
import com.sunxd.limit.beans.constants.LimitAnnotationKey;
import com.sunxd.limit.beans.params.AbsRequest;
import com.sunxd.limit.beans.params.Context;
import com.sunxd.limit.beans.params.Limit;
import com.sunxd.limit.core.AbstractLimitHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Objects;

/**
 * @author sun.xd
 * @description: description
 * @date 2024/10/22 16:58
 */
@Slf4j
@Order(4)
@Component
@LimitAnnotation(key = LimitAnnotationKey.TYPE_LIMIT, group = LimitAnnotationGroup.ACTIVITY)
public class TypeLimitHandler extends AbstractLimitHandler {

    @Override
    public Boolean judge(Context context) {
        Limit limit = getLimit(context);
        AbsRequest request = context.getRequest();
        Object value = limit.getValue();
        if (Objects.equals(value, request.getType())) {
            return Boolean.TRUE;
        }
        log.info("TypeLimitHandler warm => configValue:{}, realValue:{} ", value, request.getSuitObject());
        return Boolean.FALSE;
    }

    @Override
    public String key() {
        return LimitAnnotationKey.TYPE_LIMIT;
    }
}
